package com.huizhonglm.diap.presenters.wallet;

import com.alibaba.fastjson.JSON;
import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.api.API;
import com.huizhonglm.diap.api.HttpCallback;
import com.huizhonglm.diap.api.model.wallet.BankCardInfo;
import com.huizhonglm.diap.api.model.wallet.BankCardsParams;
import com.huizhonglm.diap.core.utils.UserUtil;
import com.huizhonglm.diap.presenters.BasePresenter;
import com.huizhonglm.diap.ui.wallet.iView.BankCardListIView;

import java.util.List;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-01 17:37
 */
public class BankCardListPersenter extends BasePresenter {

    private BankCardListIView iView;

    public BankCardListPersenter(BankCardListIView iView) {
        this.iView = iView;
    }

    public void loadBankCards(){
        BankCardsParams params = new BankCardsParams();
        params.userId = UserUtil.getUserId();
        API.http().post("getBankCards", params, new HttpCallback() {
            @Override
            public void onSuccess(String result) {
                if (!EmptyUtil.isEmpty(result)) {
                    List<BankCardInfo> data = JSON.parseArray(result, BankCardInfo.class);
                    iView.onLoadCardsSuccess(data);
                } else {
                    iView.onLoadCardsFailure();
                }
            }

            @Override
            public void onFailure(Throwable ex) {
                iView.onLoadCardsFailure();
            }
        });
    }
}
